package com.automannn.codeGenerator.core.event;


import com.automannn.codeGenerator.core.aware.ContextAware;
import com.automannn.codeGenerator.core.context.Context;

public interface  IncludeEventHandler extends EventHandler
{

     String includeEvent(String includeResourcePath, String currentResourcePath, String directiveName);




     class IncludeEventExecutor implements EventHandlerMethodExecutor
    {
        private Context context;
        private String includeResourcePath;
        private String currentResourcePath;
        private String directiveName;

        private boolean executed = false;

        IncludeEventExecutor(
                Context context,
                String includeResourcePath,
                String currentResourcePath,
                String directiveName)
        {
            this.context = context;
            this.includeResourcePath = includeResourcePath;
            this.currentResourcePath = currentResourcePath;
            this.directiveName = directiveName;
        }

        /**
         * Call the method includeEvent()
         *
         * @param handler call the appropriate method on this handler
         */
        public void execute(EventHandler handler)
        {
            IncludeEventHandler eh = (IncludeEventHandler) handler;

            if (eh instanceof ContextAware)
                ((ContextAware) eh).setContext(context);

            executed = true;
            includeResourcePath = ((IncludeEventHandler) handler)
                .includeEvent(includeResourcePath, currentResourcePath, directiveName);
        }

        public Object getReturnValue()
        {
            return includeResourcePath;
        }

        public boolean isDone()
        {
            return executed && (includeResourcePath == null);
        }


    }

}
